﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Salient.Web.Administration;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Salient.Web.Administration
{
    public partial class _Default : WebAdminPage
    {
        protected override bool CanSetApplicationPath
        {
            get
            {
                return true;
            }
        }

        protected override void OnInit(EventArgs e)
        {
            ((webAdminNoButtonRow)Master).SetNavigationBarSelectedIndex(0);
            try
            {
                SetApplicationPath();
            }
            catch
            {
                Response.Redirect("~/error.aspx");
            }
            base.OnInit(e);
        }

        public void Page_Load()
        {
            string id = Page.User.Identity.Name;
            if (id != null && !id.Equals(String.Empty))
            {
                user.Text = String.Format((string)GetLocalResourceObject("CurrentUserName"), id.ToUpper());
            }

            string appPath = ApplicationPath;
            if (appPath != null && !appPath.Equals(String.Empty))
            {
                application.Text = String.Format((string)GetLocalResourceObject("Application"), appPath);
            }
            if (IsWindowsAuth())
            {
                existingUsersLiteral.Text = (string)GetLocalResourceObject("WindowsAuth");
            }
            else
            {
                try
                {
                    int total = 0;
                    MembershipUserCollection users = (MembershipUserCollection)CallWebAdminHelperMethod(true, "GetAllUsers", new object[] { 0, Int32.MaxValue, total }, new Type[] { typeof(int), typeof(int), Type.GetType("System.Int32&") });
                    existingUsersLiteral.Text = String.Format((string)GetLocalResourceObject("ExistingUsers"), users.Count.ToString());
                }
                catch
                {
                    // Can happen, for example, if access is the default provider, but it is not available.
                    existingUsersLiteral.Visible = false;
                }
            }
        }
    }
}
